package sfeir.authform.server.authservice;

import javax.servlet.http.HttpSession;

import sfeir.authform.client.dao.AuthUser;


public class AuthServiceStandard implements AuthService {
    private static HttpSession session = null;
    private String loginURL = "/__authService/login";
    private String logoutURL = "/__authService/logout";
    private String signupURL = "/__authService/signup";
    
    public AuthServiceStandard() {
        
    }
    public AuthServiceStandard(HttpSession session) {
        AuthServiceStandard.session = session;
    }
    
    @Override
    public int getAuthType() {
        return AuthServiceFactory.STANDARD;
    }

    @Override
    public AuthUser getCurrentUser() {
        if (session == null)
            return null;
        return (AuthUser) session.getAttribute("__authService.usersession");
    }

    @Override
    public Boolean isUserAdmin() {
        return false;
    }

    @Override
    public Boolean isUserLoggedIn() {
        if (session == null)
            return false;
        return (session.getAttribute("__authService.usersession") != null);
    }

    @Override
    public String createLoginURL(String destinationURL) {
        return loginURL + "?return=" + destinationURL;
    }

    @Override
    public String createLogoutURL(String destinationURL) {
        return logoutURL + "?return=" + destinationURL;
    }
    
    public String createSignupURL(String destinationURL) {
        return signupURL + "?return=" + destinationURL;
    }

}
